<?php

function getLocationFromAddress($address){
	
	$googleMapUrl = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=".urlencode($address);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $googleMapUrl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	$page = curl_exec($ch);
	$decoded = json_decode($page);	
	if ($decoded && $decoded->results && $decoded->results[0]->geometry->location_type != "APPROXIMATE"){
		$location = array();
		$location['lat'] = $decoded->results[0]->geometry->location->lat;
		$location['lng'] = $decoded->results[0]->geometry->location->lng;
		return $location;
	}
	return false;
}

function buildMapUrl($latitude,$longitude,$size = "300x300",$maptype="roadmap"){

	$url = "http://maps.google.com/maps/api/staticmap?maptype=$maptype&sensor=false&size=$size";
	$path = "&zoom=15";
	$marker = "&markers=|".$latitude . ",". $longitude."";
	return $url . $path . $marker;
}

?>